#include <iostream>

using std::cout;
using std::endl;

class Point
{
public:
    Point(int ix = 0, int iy = 0)
    : _ix(ix)
    , _iy(iy)
    {
        cout << "Point(int,int)" << endl;
    }

    //当没有显式定义析构函数时，系统也会自动生成一个析构函数
    //当对象的生命周期结束时，析构函数会被自动调用
    //作用：用来清理对象成员所申请的资源
    ~Point() {
        cout << "~Point()" << endl;
    }

    void print() 
    {
        cout << "(" << _ix << "," << _iy << ")" << endl;
    }

private:
    int _ix;
    int _iy;
};

//当程序执行结束时，全局静态对象被销毁，此时会自动调用析构函数
Point gpt(10, 11);
static Point spt(20, 21);

int main()
{
    Point pt1(1, 2);//栈对象
    pt1.print();

    gpt.print();
    spt.print();

    //位于堆上的对象
    //int * p1 = new int(1);
    Point * p1 = new Point(30, 31);
    p1->print();

    delete p1;//通过delete表达式回收堆空间的对象
    return 0;
}

